                    <template>
  <div class="article-page">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>面经后台</el-breadcrumb-item>
      <el-breadcrumb-item>面经管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="never" border="false">
      <template #header>
        <div class="header">
          <span>共 {{ total }} 条记录</span>
          <el-button
            icon="el-icon-plus"
            size="small"
            type="primary"
            round
            @click="open('add')"
          >
            添加面经
          </el-button>
        </div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="stem" label="标题"> </el-table-column>
          <el-table-column prop="creator" label="作者"> </el-table-column>
          <el-table-column prop="likeCount" label="点赞"> </el-table-column>
          <el-table-column prop="views" label="浏览数"> </el-table-column>
          <el-table-column prop="createdAt" label="更新时间"> </el-table-column>
          <el-table-column width="110px" label="操作">
          <template #default="scope">
            <div class="actions">
                <i class="el-icon-view" @click="open('preview', scope.row.id)"></i>
                <i class="el-icon-edit-outline" @click="open('edit', scope.row.id)"></i>
                <i class="el-icon-delete" @click="del(scope.row.id)"></i>
            </div>
          </template>
         </el-table-column>
       </el-table>
       <el-pagination
          @current-change="handleCurrentChange"
          :current-page="current"
          :page-size="pageSize"
          layout=" prev, pager, next"
          :total="total"
        >
        </el-pagination>
      </template>
    </el-card>
    <el-drawer
      :title="title[type]"
      :visible.sync="isShow"
       direction="rtl"
      :before-close="handleClose"
      size="60%"
    >
      <span> <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="活动名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="活动名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">确认</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form></span>
    </el-drawer>

  </div>
</template>

<script>
import { delArticle, getArticleList } from '@/api/article'
export default {
  name: 'article-page',
  data () {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      current: 1,
      pageSize: 10,
      tableData: [],
      total: 0,
      isShow: false,
      type: 'add',
      title: {
        add: '添加面经',
        preview: '预览面经',
        edit: '修改面经'
      }

    }
  },
  created () {
    this.initData()
  },
  methods: {
    async initData () {
      const res = await getArticleList({
        current: this.current,
        pageSize: this.pageSize
      })
      // console.log(res)
      this.tableData = res.data.rows
      this.total = res.data.total
    },
    async del (id) {
      // console.log(id)
      const res = await delArticle({ id })
      console.log(res)
      this.initData()
    },
    handleCurrentChange (val) {
      this.current = val
      this.initData()
    },
    open (type, id) {
      // console.log(type, id)
      this.isShow = true
      this.type = type
    },
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 25px;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
  }
  .actions {
    font-size: 18px;
    display: flex;
    justify-content: space-around;
    color: #666;
    > i:hover {
      color: rgba(114, 124, 245, 1);
      cursor: pointer;
    }
  }
}
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
.el-breadcrumb {
  margin-top: 10px;
}
.el-form {
  padding-right: 40px;
}
.quill-editor {
  ::v-deep .ql-editor {
    height: 300px;
  }
}
.el-rate {
  padding: 10px 0;
}
.article-preview {
  padding: 0 40px 40px 40px;
  > h5 {
    font-size: 20px;
    color: #666;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 30px;
    margin: 0 0 20px 0;
  }
}
</style>
